const path = require('path')
const uglufy = require('uglifyjs-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const CleanWebpackPlugin = require('clean-webpack-plugin')
const rootPath = process.cwd()
module.exports = {
  entry: rootPath + "/src/main.js",
  output: {
    filename: "static/pc/js/bundle.js",
    publicPath: '/'
  },
  resolve: {
    alias: {
      '@com': path.join(rootPath, 'src/components'),
      '@act': path.join(rootPath, 'src/actions'),
      '@rdx': path.join(rootPath, 'src/reducers'),
      '@store': path.join(rootPath, 'src/store'),
      '@utils': path.join(rootPath, 'src/utils'),
      '@images': path.join(rootPath, 'src/images'),
      '@mock': path.join(rootPath, 'src/mock')
    }
  },
  module: {
    loaders: [
      {
        test: /\.less$/,
        use: ExtractTextPlugin.extract({
          fallback: 'style-loader',
          use: [
            {
              loader: 'css-loader',
              options: {
                minimize: true
              }
            },
            {
              loader: 'postcss-loader',
              options: {
                config: {
                  path: rootPath + '/postcss.config.js'
                }
              }
            },
            {
              loader: 'less-loader'
            }
          ]
        })
      },
      {
        test: /\.(png|jpg|gif)/,
        use: [
          {
            loader: 'url-loader',
            options: {
              limit: 20000,
              outputPath: 'static/pc/images/'
            }
          }
        ]
      },
      {
        test: /\.js$/,
        loader: 'babel-loader',
        exclude: /node_modles/,
        query: {
          presets: ['es2015', 'stage-0', 'react'],
          compact: false
        }
      }
    ]
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: rootPath + '/src/index.html',
      title: 'index',
      filename: 'index.html',
      inject: true,
    }),
    new ExtractTextPlugin('static/pc/css/app.css')
  ],
}
